import request from '@/utils/request';

// 1. 获取标签
export function getQuestions(params = {}) {
  return request({
    url: '/questions',
    method: 'post',
    data: params
  });
}

export function addQuestions(params: any = {}) {
  const { options, tags, answer, analysis, description, ...rest } = params;
  const data = {
    ...rest,
    options: options && options.length > 0 ? JSON.stringify(options) : null,
    tags: tags ? JSON.stringify(tags) : null,
    answer: answer ? (Array.isArray(answer) ? JSON.stringify(answer) : answer) : null,
    analysis: analysis ?? null,
    description: description ?? null
  };
  return request({
    url: '/addQuestion',
    method: 'post',
    data
  });
}

export function delQuestions(params = {}) {
  return request({
    url: '/delQuestion',
    method: 'post',
    data: params
  });
}

export function updateQuestions(params: any = {}) {
  const { options, tags, answer, analysis, description, ...rest } = params;
  const data = {
    ...rest,
    options: options && options.length > 0 ? JSON.stringify(options) : null,
    tags: tags ? JSON.stringify(tags) : null,
    answer: answer ? (Array.isArray(answer) ? JSON.stringify(answer) : answer) : null,
    analysis: analysis ?? null,
    description: description ?? null
  };
  return request({
    url: '/updateQuestions',
    method: 'post',
    data
  });
}

export function uploadQuestions(params = {}) {
  return request({
    url: '/uploadQuestions',
    method: 'post',
    data: params
  });
}
